package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.PromissGroup;
import cn.wolfcode.crm.mapper.DicitemMapper;
import cn.wolfcode.crm.mapper.PromissGroupMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IPromissGroupService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class PromissGroupServiceImpl implements IPromissGroupService {

    @Autowired
    private PromissGroupMapper promissgroupMapper;

    @Autowired
    private DicitemMapper dicitemMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return promissgroupMapper.deleteByPrimaryKey(id);
    }


    @Override
    public PromissGroup selectByPrimaryKey(Long id) {
        return promissgroupMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PromissGroup> selectAll() {
        return promissgroupMapper.selectAll();
    }

    @Override
    public int insert(PromissGroup entity) {
        return promissgroupMapper.insert(entity);
    }

    public int updateByPrimaryKey(PromissGroup entity, String promisename,Long ids) {

        dicitemMapper.updateByPromiss(promisename,entity.getId());
        return promissgroupMapper.updateByPrimaryKey(entity);
    }

    @Override
    public void changeState(Long id) {
        promissgroupMapper.changeState(id);
    }
    //分页
    public PageResult query(QueryObject qo) {
        int total = promissgroupMapper.query4Count(qo);
        if (total == 0) {
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        List<?> rows = promissgroupMapper.query4List(qo);
        return new PageResult(total, rows);
    }
}
